/*
Makra: MATRIX CONSTANT_COLOR VERTEX_COLOR TEXTURE COLOR_MATRIX COLOR_ADD
*/

#if MATRIX != 0
	float4x4 g_Matrix;
#endif

#if CONSTANT_COLOR != 0
	float4 g_ConstantColor;
#endif

#if TEXTURE != 0
	texture g_Texture;
	sampler Sampler = sampler_state
	{
		Texture = (g_Texture);
	};
#endif

#if COLOR_MATRIX != 0
	float4x4 g_ColorMatrix;
#endif

#if COLOR_ADD != 0
	float4 g_ColorAdd;
#endif

struct APP_TO_VS
{
	float4 Pos : POSITION;
	#if VERTEX_COLOR != 0
		float4 VertexColor : COLOR0;
	#endif
	#if TEXTURE != 0
		float2 TexCoord : TEXCOORD0;
	#endif
};

struct VS_TO_PS
{
	float4 Pos : POSITION;
	#if VERTEX_COLOR != 0
		float4 VertexColor : COLOR0;
	#endif
	#if TEXTURE != 0
		float2 TexCoord : TEXCOORD0;
	#endif
};

void MainVS(in APP_TO_VS In, out VS_TO_PS Out)
{
	#if MATRIX != 0
		Out.Pos = mul(In.Pos, g_Matrix);
	#else
		Out.Pos = In.Pos;
	#endif
	
	#if VERTEX_COLOR != 0
		Out.VertexColor = In.VertexColor;
	#endif
	
	#if TEXTURE != 0
		Out.TexCoord = In.TexCoord;
	#endif
}

void MainPS(in VS_TO_PS In, out float4 Out : COLOR0)
{
	Out = float4(1, 1, 1, 1);

	#if CONSTANT_COLOR != 0
		Out *= g_ConstantColor;
	#endif

	#if VERTEX_COLOR != 0
		Out *= In.VertexColor;
	#endif
	
	#if TEXTURE != 0
		Out *= tex2D(Sampler, In.TexCoord);
	#endif
	
	#if COLOR_MATRIX != 0
		Out = mul(Out, g_ColorMatrix);
	#endif
	
	#if COLOR_ADD != 0
		Out += g_ColorAdd;
	#endif
}

technique {
	pass {
		VertexShader = compile vs_3_0 MainVS();
		PixelShader  = compile ps_3_0 MainPS();
	}
}

